package com.qf.controller;

import com.qf.annotation.RequiresPermissionsDesc;
import com.qf.service.GoodsService;
import com.qf.service.OrderService;
import com.qf.service.UserService;
import com.qf.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * projectName: shop-manage
 *
 * @author: 元
 * time: 2021/9/13 0013 22:42
 * description:统计
 */
@RestController
@CrossOrigin("*")
@RequestMapping("/stat")
public class StatisticController {

    @Autowired
    private UserService userService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private GoodsService goodsService;


    public static final Logger logger = LoggerFactory.getLogger(AdminAuthController.class);

    //用户统计
    @GetMapping("/user")
    public Object statUser(){
        Map data = new HashMap();
        String [] columns = {"day","users"};
        List<Map> rows = userService.statUserByPage();
        data.put("columns",columns);
        data.put("rows",rows);
        logger.info("[分页查询用户]查询完毕,获取数据为:{}",columns,rows);
        return ResponseUtil.ok(data);
    }

    //订单统计
    @GetMapping("order")
    public Object statOrder(){
        Map data = new HashMap();
        String [] columns = {"day","orders","customers","amount","pcr"};

        List<Map> rows = orderService.statOrderByday();
        data.put("columns",columns);
        data.put("rows",rows);
        return ResponseUtil.ok(data);
        }

    //商品统计
    @GetMapping("goods")
    public Object statGoods(){
        Map data = new HashMap();
        String [] columns = {"day","orders","products","amount"};
        data.put("columns",columns);
        List<Map> rows =goodsService.statGoodsByDay();
        data.put("rows",rows);
        return ResponseUtil.ok(data);

    }


}
